package com.java.zhuiyun.api.sysmenu.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.java.zhuiyun.api.sysmenu.entity.Menu;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.mapstruct.Mapper;

import java.util.List;

/**
 * @InterfaceName MenuMapper
 * @Description TODO
 * @Author xy
 * @Date 2023/8/16 16:26
 **/
@Mapper
public interface MenuMapper extends BaseMapper<Menu> {

    /**
     * @Author xy
     * @Description 全查
     * @Date 2023/8/15 18:49
     * @Return  * @param null
     */
    @Select("<script>select * from sys_menu where del_flag = 0 <when test='mname != null and mname != &quot;&quot;'> " +
            "and mname like concat('%', #{mname}, '%') </when></script>")
    List<Menu> MenuList();

    @Select("<script>select * from sys_menu where del_flag = 0 <when test='mname != null and mname != &quot;&quot;'> " +
            "and mname like concat('%', #{mname}, '%') </when> " +
            "order by sort_num asc</script>")
    List<Menu> customSearch();

    @Select("select * from sys_menu")
    List<Menu> selectList();

    @Select("select * from sys_menu where id = #{menuId}")
    Menu getById(Integer menuId);

    /**
     * @Author xy
     * @Description 添加
     * @Date 2023/8/15 20:10
     * @Return  * @param null
     */
    @Insert("insert into sys_menu (mname,path,icon,description,pid,page_path,sort_num,create_time,update_time) values " +
            "(#{mname},#{path},#{icon},#{description},#{pid},#{pagePath},#{sortNum},#{createTime},#{updateTime})")
    int MenuAdd(Menu menu);

    /**
     * @Author xy
     * @Description 逻辑删除
     * @Date 2023/8/15 16:41
     * @Return  * @param null
     */
    @Update("update sys_menu set del_flag = 1 where id = #{id}")
    int MenuDelete(Integer id);

    /**
    * @Author xy
    * @Description 修改
    * @Date 2023/8/17 9:41
    * @Return  * @param null
    */
    @Update("update sys_menu set mname = #{mname},path = #{path},icon = #{icon}," +
            "description = #{description},page_path = #{pagePath},sort_num = #{sortNum}," +
            "update_time = #{updateTime} where id = #{id}")
    int Menuupdate(Menu menu);

    /**
    * @Author xy
    * @Description 修改目录
    * @Date 2023/9/3 22:42
    * @Return  * @param null
    */
    @Update("update sys_menu set pid = #{pid},mname = #{mname} where id = #{id}")
    int updateml(Menu menu);

}
